﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Plugins
{
    public class PluginsPlugin : IPlugin
    {
        #region IPlugin Members
        public string Name { get { return "Plugin Manager"; } }
        public List<string> Command
        {
            get { return new List<string>() { "plugin", "help" }; }
        }

        public string RootStore { get; set; }

        public MSNPSharp.Messenger Messenger { get; set; }

        public string Chat(string Command, string UserID, string Input)
        {

            if (Command == "help")
            {
                System.Text.StringBuilder sb = new StringBuilder();
                foreach (IPlugin plug in PluginLoader.PluginList)
                {
                    sb.Append(string.Format("{0}, Commands: ", plug.Name));
                    foreach (string cmd in plug.Command)
                    {
                        sb.Append(cmd);
                        sb.Append(",");
                    }
                    sb.Append("\n");
                }
                sb.Append("--End");
                return sb.ToString();
            }
            else
            {

                string owner = System.Configuration.ConfigurationSettings.AppSettings["Owner"];
                if (UserID == owner)
                {
                    string[] parts = Input.Split(' ');
                    string subCommand = parts[0].ToLower();

                    if (subCommand == "reload")
                    {
                        PluginLoader.LoadPlugins();
                        PluginLoader.Messenger = this.Messenger;
                        PluginLoader.RootStore = this.RootStore;
                    }
                }
                return "";
            }
        }

        #endregion
    }
}